package com.siae.controller;


import com.siae.pojo.UploadFile;
import com.siae.pojo.vo.Result;
import com.siae.service.UploadFileService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/file")
@Tag(name = "FileController",description = "文件操作")
public class UploadFileController {
    @Autowired
    private UploadFileService uploadFileService;

    @GetMapping
    public Result<List<UploadFile>> getFilePath(
            @RequestParam(name = "id",defaultValue = "") Integer id,
            @RequestParam(name = "filePath",defaultValue = "") String filePath){
        return uploadFileService.getFilePath(id, filePath);
    }
    @GetMapping("/{id}")
    public Result<UploadFile> getUploadFileById(@PathVariable("id") Integer id){
        return uploadFileService.getUploadFileById(id);
    }
    @PostMapping
    public Result addUploadFile(@RequestBody UploadFile uploadFile){
        return uploadFileService.addUploadFile(uploadFile);
    }
    @PutMapping
    public Result updateFile(@RequestBody UploadFile uploadFile){
        return uploadFileService.updateFile(uploadFile);
    }
    @DeleteMapping("/{id}")
    public Result deleteFile(@PathVariable("id") Integer id){
        return uploadFileService.deleteFile(id);
    }
}